
// gloab namespace lemon
var Lemon = {};

var settingForLemonMenu = {
		isSimpleData : true, //数据是否采用简单 Array 格式，默认false  
		treeNodeKey : "id", //在isSimpleData格式下，当前节点id属性  
		treeNodeParentKey : "pId", //在isSimpleData格式下，当前节点的父节点id属性  
		showLine : true
	//是否显示节点间的连线  
	// checkable : true                  //每个节点上是否显示 CheckBox
	};
$(function(){
	$.ajax({
		type : 'POST',
		dataType : "html",
		url : 'goal/menu.action',
		error : function() {
			alert('请求失败');
		},
		success : function(data) {
			var treeNodes = eval(data);
			var lemonMenuHorizonId = "lemonMenuHorizon";
			var lemonMenuVerticalId = "lemonMenuVertical";
			var lemonMenuId = "lemonMenu";
			var $lemonMenuHorizon = $('#' + lemonMenuHorizonId);
			var $lemonMenuVertical = $('#' + lemonMenuVerticalId);
			var $lemonMenuTree = $('#' + lemonMenuId + '_tree');
			// generate the ul li list
			var zTree = $lemonMenuTree.zTree(settingForLemonMenu, treeNodes);
			// remove unuse element generate by ztree
			$lemonMenuTree.find('div').remove();
			$lemonMenuTree.find('button').remove();
			$lemonMenuTree.removeClass('tree');
			// remove the span and hiden ul by ztree
			$lemonMenuTree.find('span').each(function(){
				var $span = $(this);
				var $a = $span.parent();
				var $ul_hide = $a.next();
				var urlName = $span.text();
				$a.removeAttr('target');
				if(!($ul_hide.children().length > 0))
					$ul_hide.remove();
				$span.parent().empty().text(urlName);
			});
			
			var ul = $lemonMenuTree.parent().html() ;
			$lemonMenuHorizon.append(ul);
			
			$lemonMenuTree.addClass("jd_menu_vertical");
			var ul_vertical = $lemonMenuTree.parent().html();
			$lemonMenuVertical.append(ul_vertical);
			$('ul.jd_menu').jdMenu();
		}
		});
});
